var BusCon = require("../../core/bus/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");
var UserCon = require("../../core/user/_con");
var BuffCon = require("../../core/buff/_con");
var myfs = require("../_include/fs");
var theme = require("./theme");
var role = require("./role");

module.exports = {
	prefix: "/user/card",
	get: {
		"/list": function() {
			var user = role.getUser(this);
			var query = this.request.query;
			var card_list = user.getCardList(query.state);
			this.body = ResponObj("json", card_list);
		},
		"/by_id/:card_id": function() {
			var user = role.getUser(this);
			var card_id = this.params.card_id;
			this.body = ResponObj("json", user._getCard(card_id));
		},
		"/list/by_bus_id/:bus_id": function() {
			var user = role.getUser(this);
			var bus_id = this.params.bus_id;
			this.body = ResponObj("json", user.getCardListByBusId(bus_id));
		},
		"/goods_list_with_page_info": function() {
			var user = role.getUser(this);
			var query = this.request.query;
			this.body = ResponObj("json", user.getCardFactoryGoodsListFromBus_PageInfo(query.bus_id, query.num, query.page));
		},
	},
	post: {
		"/add_card_from_card_factory/:card_factory_id": function() {
			var user = role.getUser(this);
			var card_factory_id = this.params.card_factory_id;
			var card = user.addCardFromCardFactory(card_factory_id);
			this.body = ResponObj("json", card);
		},
		"/add_card_from_card_factory/need_buy_cb/:card_factory_id": function() {
			// 购买会员卡，支持成功的回调
			var query = this.request.query;
			var user_id = query.user_id;
			var ach_id = query.ach_id;
			var user = UserCon.get(user_id);
			var card = user._addCardFromCardFactoryNeedBuyCb(ach_id, this.params.card_factory_id);
			this.body = "success"
		},
	}
}